# from model.Testcase_model import TestcaseModel
# from public.db import db_session
# from manager import app


# class TestcaseMapper:
#
#     def save(self, testcase_body: TestcaseModel):
#         with app.app_context():
#             db_session.add(testcase_body)
#             db_session.commit()
#
#     def get(self, id) -> TestcaseModel:
#         with app.app_context():
#             return db_session.query(TestcaseModel).filter_by(id=id).first()
#
#     def get_all(self):
#         # return db_session.query(TestcaseDo).all()
#         with app.app_context():
#             return TestcaseModel.query.all()
#
#     def delete(self, id):
#         with app.app_context():
#             db_session.query(TestcaseModel).filter_by(id=id).delete()
#             db_session.commit()
#
#     def update(self, id, update_data):
#         with app.app_context():
#             db_session.query(TestcaseModel).filter_by(id=id).update(update_data)
#             db_session.commit()


from model.Testcase_model import TestcaseModel
from public.db import db_session


class TestcaseMapper:

    def save(self, testcase_body: TestcaseModel):

        db_session.add(testcase_body)
        db_session.commit()

    def get(self, id) -> TestcaseModel:
        return db_session.query(TestcaseModel).filter_by(id=id).first()

    def get_all(self):

        # return db_session.query(TestcaseDo).all()
        return TestcaseModel.query.all()

    def delete(self, id):

        db_session.query(TestcaseModel).filter_by(id=id).delete()
        db_session.commit()

    def update(self, id, update_data):

        db_session.query(TestcaseModel).filter_by(id=id).update(update_data)
        db_session.commit()
